package vip.george.sentinel2.controller;


import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import vip.george.common.dto.ResultVO;
import vip.george.sentinel2.service.PayService;

import java.util.concurrent.TimeUnit;

/**
 * @author george
 * @since 2023/7/11
 * <p>服务熔断降级测试</p>
 */

@RestController
@RequestMapping("/degrade")
public class DegradeTestController {

    @Autowired
    private PayService payService;


    @GetMapping("/slowRT")
    @SentinelResource(value = "slowRT", blockHandler = "afterBlock")
    public ResultVO<String> callBack() throws InterruptedException {
        System.out.println("模拟慢调用");
        TimeUnit.SECONDS.sleep(3);
        return ResultVO.success("slowRT success");
    }

    public ResultVO<String> afterBlock(BlockException ex){
        ex.printStackTrace();
        return ResultVO.success("被熔断降级！！！");
    }



}
